<template>
  <div class="app-container">
    <!-- 头部 Button -->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-search"
          size="mini"
          @click="handleSearch"
          >搜索</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-aim"
          size="mini"
          :disabled="single"
          @click="handleAnalyse"
          v-hasPermi="['device:equipmentRepairCheck:analyse']"
        >
          分析
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-s-check"
          size="mini"
          :disabled="single"
          @click="handleCheck"
          v-hasPermi="['device:equipmentRepairCheck:check']"
        >
          维修完成
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="single"
          @click="check_remove = true"
          v-hasPermi="['device:equipmentRepairCheck:back']"
        >
          撤回
        </el-button>
      </el-col>

      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['device:equipmentRepair:export']"
        >
          导出
        </el-button>
      </el-col>
      <Tag type="dot" size="default" color="#0fac09">提交</Tag>
      <Tag type="dot" size="default" color="#0323af">审核</Tag>
      <Tag type="dot" size="default" color="#bb0331">验收</Tag>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <!-- 主表数据 -->
    <el-table
      @scrollBottom="load"
      highlight-current-row
      border
      stripe
      v-loading="loading"
      :cell-style="iCellStyle"
      :data="WxmMstrList"
      @row-click="clickRow"
      :header-cell-style="{ 'text-align': 'center' }"
      :height="tableH"
    >
      <el-table-column label="#" width="40" type="index" align="center" />
      <el-table-column
        label="维修单号"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="wxmDjbh"
      />
      <el-table-column
        label="设备代码"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="wxmSbdm"
      />
      <el-table-column
        label="设备名称"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="wxmSbName"
      />
      <el-table-column
        label="申请部门"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="wxmBmdm"
      >
        <template v-slot="scope">
          <dict-tag :options="deptList" :value="scope.row.wxmBmdm" />
        </template>
      </el-table-column>
      <el-table-column
        label="申请人员"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="wxmSqry"
      />
      <el-table-column
        label="停机时间"
        :show-overflow-tooltip="true"
        align="center"
        prop="wxmKssj"
        width="180"
      />
      <el-table-column
        label="维修时间"
        :show-overflow-tooltip="true"
        align="center"
        prop="wxmWxsj"
        width="180"
      />
      <el-table-column
        label="维修工时"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="wxmWxgs"
      />
      <el-table-column
        label="维修人员"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="wxmWxry"
      />
      <el-table-column
        label="撤回原因"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="wxmNgdesc"
      />
      <el-table-column
        label="建立人员"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="wxmJlry"
      />
      <el-table-column
        label="建立日期"
        :show-overflow-tooltip="true"
        align="center"
        prop="wxmJlrq"
        width="180"
      />
      <el-table-column
        label="分析人员"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="wxmFxry"
      />
      <el-table-column
        label="分析日期"
        :show-overflow-tooltip="true"
        align="center"
        prop="wxmFxrq"
        width="180"
      />
      <el-table-column
        label="验收人员"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="wxmPzry"
      />
      <el-table-column
        label="验收日期"
        :show-overflow-tooltip="true"
        align="center"
        prop="wxmPzrq"
        width="180"
      />
      <el-table-column
        label="总停机时间（小时）"
        :show-overflow-tooltip="true"
        align="center"
        prop="wxmZjsj"
        width="140"
      />
    </el-table>

    <!--子表Tab-->
    <el-tabs v-model="activeTab">
      <el-tab-pane label="申请及维修内容" name="first">
        <el-form ref="form" :model="wxmMstr" label-width="100px">
          <el-col :span="6">
            <el-form-item label="维修单号" prop="wxmDjbh">
              <el-input v-model="wxmMstr.wxmDjbh" readonly />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="申请人员" prop="wxmSqry">
              <el-input v-model="wxmMstr.wxmSqry" readonly />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="申请部门" prop="wxmBmdm">
              <el-input v-model="wxmMstr.wxmBmdm" readonly />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="设备代码" prop="wxmSbdm">
              <el-input v-model="wxmMstr.wxmSbdm" readonly />
            </el-form-item>
          </el-col>

          <el-col :span="6">
            <el-form-item label="设备名称" prop="wxmSbName">
              <el-input v-model="wxmMstr.wxmSbName" readonly />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="维修人员" prop="wxmWxry">
              <el-input v-model="wxmMstr.wxmWxry" readonly />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="维修工时" prop="wxmWxgs">
              <el-input v-model="wxmMstr.wxmWxgs" readonly />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="建立人员" prop="wxmJlry">
              <el-input v-model="wxmMstr.wxmJlry" readonly />
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="分析人员" prop="wxmFxry">
              <el-input v-model="wxmMstr.wxmFxry" readonly />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="停机时间" prop="wxmKssj">
              <el-input v-model="wxmMstr.wxmKssj" readonly />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="维修时间" prop="wxmWxsj">
              <el-input v-model="wxmMstr.wxmWxsj" readonly />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="故障原因" prop="wxmGzms">
              <el-input type="textarea" v-model="wxmMstr.wxmGzms" readonly />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="原因处理" prop="wxmClms">
              <el-input type="textarea" v-model="wxmMstr.wxmClms" readonly />
            </el-form-item>
          </el-col>
        </el-form>
      </el-tab-pane>
      <el-tab-pane label="更换零件清单" name="second">
        <el-table
          border
          stripe
          :data="wxdDetList"
          :height="tableHChild"
          :header-cell-style="{ 'text-align': 'center' }"
        >
          <el-table-column label="#" type="index" width="40" align="center" />
          <el-table-column label="部件名称" align="center" prop="wxdPmgg" />
          <el-table-column label="数量" align="center" prop="wxdSl" />
          <el-table-column label="单价(元)" align="center" prop="wxdCgdj" />
          <el-table-column label="金额(元)" align="center" prop="wxdCgje" />
          <el-table-column label="备注" align="center" prop="wxdDesc" />
        </el-table>
      </el-tab-pane>
      <el-tab-pane label="部门验收" name="third">
        <el-form ref="form" :model="wxmMstr" label-width="100px">
          <el-col :span="12">
            <el-form-item label="验收人员" prop="wxmPzry">
              <el-input v-model="wxmMstr.wxmPzry" readonly />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="部门验收" prop="wxmYsms">
              <el-input type="textarea" v-model="wxmMstr.wxmYsms" readonly />
            </el-form-item>
          </el-col>
        </el-form>
      </el-tab-pane>
    </el-tabs>

    <!-- 查询对话框 -->
    <el-dialog
      :title="title"
      v-model="openSearch"
      :close-on-click-modal="false"
      draggable
      width="420px"
      append-to-body
    >
      <el-form
        :model="queryParams"
        ref="queryForm"
        :inline="true"
        v-show="showSearch"
        label-width="88px"
      >
        <el-col :span="24">
          <el-form-item label="建立日期">
            <el-date-picker
              v-model="dateRange"
              size="small"
              style="width: 240px"
              value-format="yyyy-MM-dd"
              type="daterange"
              range-separator="-"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            ></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="维修单号" prop="wxmDjbh">
            <el-input
              class="input240"
              v-model="queryParams.wxmDjbh"
              placeholder="请输入维修单号"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="设备代码" prop="wxmSbdm">
            <el-input
              class="input240"
              v-model="queryParams.wxmSbdm"
              placeholder="请输入设备名称"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="设备名称" prop="wxmSbName">
            <el-input
              class="input240"
              v-model="queryParams.wxmSbName"
              placeholder="请输入设备名称"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="24" style="text-align: center">
          <el-form-item prop="wxmZtbz">
            <el-radio-group v-model="queryParams.wxmZtbz">
              <el-radio label="1">未维修</el-radio>
              <el-radio label="2">已维修</el-radio>
              <el-radio label="">全部</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item
            style="margin-top: 25px; display: flex; justify-content: flex-end"
          >
            <el-button @click="cancel">取消</el-button>
            <el-button type="primary" @click="handleQuery">确认</el-button>
          </el-form-item>
        </el-col>
      </el-form>
    </el-dialog>

    <!-- 分析设备维修单对话框 -->
    <el-dialog
      :title="title"
      v-model="open"
      :close-on-click-modal="false"
      draggable
      width="780px"
      append-to-body
    >
      <el-tabs v-model="activeTab">
        <el-tab-pane label="故障原因处理" name="first">
          <el-form ref="form" :model="form" :rules="rules" label-width="100px">
            <el-col :span="24">
              <el-form-item label="维修时间" prop="wxmWxsj">
                <el-date-picker
                  clearable
                  size="small"
                  v-model="form.wxmWxsj"
                  type="datetime"
                  value-format="yyyy-MM-dd HH:mm:ss"
                  placeholder="选择维修时间"
                ></el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="维修人员" prop="wxmWxry">
                <el-input v-model="form.wxmWxry" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="维修工时" prop="wxmWxgs">
                <el-input-number v-model="form.wxmWxgs" />
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="原因处理" prop="wxmClms">
                <el-input type="textarea" v-model="form.wxmClms"></el-input>
              </el-form-item>
            </el-col>
          </el-form>
        </el-tab-pane>
        <el-tab-pane label="更换零件" name="second">
          <el-table
            highlight-current-row
            border
            stripe
            :data="wxdDetList"
            v-loading="loading"
            @row-click="clickWxdRow"
            height="300"
            :header-cell-style="{ 'text-align': 'center' }"
          >
            <el-table-column label="#" type="index" width="40" align="center" />
            <el-table-column
              label="部件名称"
              width="135"
              align="center"
              prop="wxdPmgg"
            />
            <el-table-column
              label="数量"
              :show-overflow-tooltip="true"
              align="center"
              prop="wxdSl"
            />
            <el-table-column
              label="单价(元)"
              :show-overflow-tooltip="true"
              align="center"
              prop="wxdCgdj"
            />
            <el-table-column
              label="金额(元)"
              :show-overflow-tooltip="true"
              align="center"
              prop="wxdCgje"
            />
            <el-table-column
              label="备注"
              :show-overflow-tooltip="true"
              align="center"
              prop="wxdDesc"
            />
          </el-table>
          <el-button type="primary" @click="handAddWxd">新 增</el-button>
          <el-button type="primary" @click="handDelWxd">删 除</el-button>
        </el-tab-pane>
      </el-tabs>

      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
        <el-button type="primary" @click="submitForm">确 定</el-button>
      </div>
    </el-dialog>

    <!-- 零件选取 -->
    <el-dialog
      :title="titleWxd"
      v-model="wxdOpen"
      :close-on-click-modal="false"
      draggable
      width="620px"
      append-to-body
    >
      <el-form
        :model="queryParamsChild"
        ref="queryForm"
        :inline="true"
        v-show="showSearch"
        label-width="68px"
      >
        <el-col :span="24">
          <el-form-item label="筛选条件" prop="itmPmgg">
            <el-input
              v-model="queryParamsChild.itmPmgg"
              clearable
              style="width: 370px"
              size="small"
              @input="searchIqm"
            />
          </el-form-item>
        </el-col>
        <el-table
          highlight-current-row
          border
          stripe
          @scrollBottom="load1"
          v-loading="loading"
          height="300"
          :data="iqmList"
          @selection-change="handleWxdSelection"
          :header-cell-style="{ 'text-align': 'center' }"
        >
          <el-table-column label="#" type="index" width="40" align="center" />
          <el-table-column type="selection" align="center" />
          <el-table-column label="零件代码" prop="itmWldm" align="center" />
          <el-table-column
            label="品名规格"
            :show-overflow-tooltip="true"
            align="center"
            prop="itmPmgg"
          />
          <el-table-column
            label="数量"
            :show-overflow-tooltip="true"
            align="center"
          >
            <template #default="scope">
              <el-input type="number" v-model="scope.row.wxdSl"></el-input>
            </template>
          </el-table-column>
          <el-table-column
            label="备注"
            :show-overflow-tooltip="true"
            align="center"
          >
            <template #default="scope">
              <el-input v-model="scope.row.wxdDesc"></el-input>
            </template>
          </el-table-column>
        </el-table>
        <el-col :span="24">
          <el-form-item
            style="margin-top: 25px; display: flex; justify-content: flex-end"
          >
            <el-button @click="wxdOpen = false">取消</el-button>
            <el-button type="primary" @click="handleAddWxd">确认</el-button>
          </el-form-item>
        </el-col>
      </el-form>
    </el-dialog>

    <!-- 撤回 -->
    <Modal v-model="check_remove" draggable scrollable width="300">
      <p slot="header" style="color: #f60; text-align: center">
        <Icon type="ios-information-circle"></Icon>
        <span>确认撤回？</span>
      </p>
      <div style="text-align: center">
        <p>确认将此单据撤回重写吗</p>
        <Input style="width: 90%" v-model="backReason" placeholder="撤回原因" />
      </div>
      <div slot="footer">
        <Button type="error" size="large" long @click="handleBack">撤回</Button>
      </div>
    </Modal>
  </div>
</template>

<script>
import {
  listEquipmentRepair,
  getEquipmentRepair,
  getWxdDet,
  addWxd,
  delWxd,
  updateEquipmentRepair,
  checkWxm,
  backCheckWxm,
  backAccpetWxm,
  exportModelRepair,
} from "@/api/device/equipmentRepair";
import { listDept } from "@/api/system/dept";
import { userDict } from "@/api/system/user";
import { getIqmByPmgg } from "@/api/project/iqmMstr";
import { listDeviceAll } from "@/api/device/preservePlan";

export default {
  name: "EquipmentRepairCheck",
  data() {
    return {
      // 遮罩层
      loading: true,
      tableH: (document.body.clientHeight - 130) / 2,
      tableHChild: (document.body.clientHeight - 280) / 2,
      // 选中数组
      rowData: null,
      //选中的子项数组
      wxdId: null,
      // 非单个禁用
      single: true,
      // 显示搜索条件
      showSearch: true,
      openSearch: false,
      // 总条数
      total: 0,
      totalIqm: 0,
      // 设备维修单表格数据
      WxmMstrList: [],
      wxdDetList: [],
      // 非生产物料信息表
      iqmList: [],
      // 选中的零件
      wxdSelected: [],
      // 全部部门
      deptList: [],
      //用户
      UserOptions: [],
      // 弹出层标题
      title: "",
      titleWxd: "",
      //显示的表格
      activeTab: "first",
      // 是否显示弹出层
      open: false,
      // 撤回弹出层
      check_remove: false,
      //撤回
      backReason: null,
      // 新增子项弹出层
      wxdOpen: false,
      // 建立日期时间范围
      dateRange: [
        new Date(new Date().getTime() - 1000 * 60 * 60 * 24 * 60),
        new Date(new Date().getTime() + 1000 * 60 * 60 * 24 * 60),
      ],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 25,
        wxmDjbh: null,
        wxmSbName: null,
        wxmJlrq: null,
        wxmZtbz: "1",
        wxmTjflag: "1",
      },
      queryParamsChild: {
        pageNum: 1,
        pageSize: 25,
        itmPmgg: null,
      },
      // 表单参数
      form: {},
      wxmMstr: {},
      // 表单校验
      rules: {
        wxmWxry: [
          { required: true, message: "维修人员不能为空", trigger: "blur" },
        ],
      },
    };
  },
  created() {
    //用户字典
    userDict().then((res) => {
      this.UserOptions = res.data;
    });
    // 获取全部部门
    listDept().then((res) => {
      this.deptList = res.data;
      for (let item of this.deptList) {
        item.dictLabel = item.deptName;
        item.listClass = "default";
        item.dictValue = item.deptId + "";
      }
    });
    this.getList();
  },
  methods: {
    /** 颜色事件 */
    iCellStyle: function ({ row, column, rowIndex, columnIndex }) {
      //提交
      if (row.wxmZtbz == "1" && row.wxmTjflag == "1") {
        return "padding:0px 0;color:#0fac09";
      }
      //审核
      else if (row.wxmZtbz == "2" && row.wxmTjflag == "1") {
        return "padding:0px 0;color:#0323af";
      }
      //验收
      else if (row.wxmZtbz == "4" && row.wxmTjflag == "1") {
        return "padding:0px 0;color:#bb0331";
      }
    },
    /** 查询设备维修单列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.dateRange && "" != this.dateRange) {
        this.queryParams.params["beginWxmJlrq"] = this.moment(
          this.dateRange[0]
        ).format("YYYY-MM-DD HH:mm:ss");
        this.queryParams.params["endWxmJlrq"] = this.moment(
          this.dateRange[1]
        ).format("YYYY-MM-DD HH:mm:ss");
      }
      this.queryParams.pageNum = 1;
      listEquipmentRepair(this.queryParams).then((response) => {
        this.WxmMstrList = [];
        this.WxmMstrList = this.WxmMstrList.concat(response.rows);
        this.total = response.total;
        this.loading = false;
        this.wxdDetList = [];
        this.wxmMstr = {};
        if (this.rowData == null) {
          this.clickRow(this.WxmMstrList[0]);
        }
      });
    },
    // 获取子项数据
    getWxmDet(wxmId, wxmDjbh) {
      getEquipmentRepair(wxmId).then((response) => {
        this.wxmMstr = response.data;
      });
      this.getWxd(wxmDjbh);
    },
    getWxd(wxmDjbh) {
      getWxdDet(wxmDjbh).then((res) => {
        this.wxdDetList = res.data;
      });
    },

    //load
    load() {
      if (
        this.queryParams.pageNum <
        Math.ceil(this.total / this.queryParams.pageSize)
      ) {
        this.queryParams.pageNum++;
        listEquipmentRepair(this.queryParams).then((response) => {
          this.WxmMstrList = this.WxmMstrList.concat(response.rows);
          this.total = response.total;
          this.loading = false;
        });
      }
      return 0;
    },
    load1() {
      if (
        this.queryParamsChild.pageNum <
        Math.ceil(this.totalIqm / this.queryParamsChild.pageSize)
      ) {
        this.queryParamsChild.pageNum++;
        listDeviceAll(this.queryParamsChild).then((res) => {
          this.iqmList = this.iqmList.concat(res.rows);
          this.totalIqm = res.total;
        });
      }
      return 0;
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.openSearch = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        wxmId: null,
        wxmDjbh: null,
        wxmSbdm: null,
        wxmSbName: null,
        wxmBmdm: null,
        wxmSqry: null,
        wxmKssj: new Date(),
        wxmGzms: null,
        wxmClms: null,
        wxmYsms: null,
        wxmWxry: null,
        wxmWxgs: null,
        wxmWxsj: null,
        wxmTjflag: null,
        wxmZtbz: null,
        wxmNgdesc: null,
        wxmJlry: null,
        wxmJlrq: null,
        wxmFxry: null,
        wxmFxrq: null,
        wxmPzry: null,
        wxmPzrq: null,
      };
      this.resetForm("form");
    },
    //搜索
    handleSearch() {
      this.reset();
      this.title = "查询设备维修单";
      this.openSearch = true;
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.WxmMstrList = [];
      this.getList();
      this.openSearch = false;
    },
    // 多选框选中数据
    clickRow(row) {
      if (row != null) {
        this.rowData = row;
        this.getWxmDet(row.wxmId, row.wxmDjbh);
      }
      this.single = row == null || row.wxmZtbz != "1" || row.wxmTjflag != "1";
    },
    /** 分析按钮操作 */
    handleAnalyse() {
      this.reset();
      const wxmId = this.rowData.wxmId;
      getEquipmentRepair(wxmId).then((response) => {
        this.form = response.data;
        if (this.form.wxmWxsj == null) {
          this.form.wxmWxsj = this.moment().format();
        }
        this.open = true;
        this.title = "分析-资料录入";
      });
    },
    /** 新增-Wxd子项数据 */
    handAddWxd() {
      this.searchIqm();
      this.titleWxd = "设备选取";
      this.wxdOpen = true;
    },
    /** 删除-Wxd子项数据 */
    handDelWxd() {
      if (this.wxdId == "" || this.wxdId == null) {
        alert("未选中到有效的数据,请核对");
        return;
      } else {
        delWxd(this.wxdId)
          .then((res) => {
            this.getWxd(this.rowData.wxmDjbh);
            this.msgSuccess("删除成功");
          })
          .catch(() => {
            this.msgError("删除失败");
          });
      }
    },
    /** 查询零件 */
    searchIqm() {
      getIqmByPmgg(this.queryParamsChild)
        .then((res) => {
          this.iqmList = res.rows;
        })
        .catch(() => {
          this.msgError("查询失败");
        });
    },
    /** 零件选取 */
    handleWxdSelection(selection) {
      this.wxdSelected = selection;
    },
    /** 保存选中的零件 */
    handleAddWxd() {
      const wxdDjbh = this.rowData.wxmDjbh;
      let data = [];
      for (let i of this.wxdSelected) {
        if (i.wxdSl == null || i.wxdSl <= 0) {
          alert("选择的:【" + i.itmPmgg + "】数量不能为0");
          return;
        } else {
          data.push({
            wxdDjbh,
            wxdWldm: i.itmWldm,
            wxdSl: i.wxdSl,
            wxdCgdj: i.itmPrice,
            wxdDesc: i.wxdDesc,
          });
        }
      }
      addWxd(data)
        .then((res) => {
          this.wxdOpen = false;
          this.getWxd(wxdDjbh);
          this.msgSuccess("添加成功");
        })
        .catch(() => {
          this.msgError("添加失败");
        });
    },
    clickWxdRow(row) {
      this.wxdId = row.wxdId;
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          updateEquipmentRepair(this.form).then((response) => {
            this.msgSuccess("成功");
            this.open = false;
            this.getList();
          });
        }
      });
    },
    /** 审核按钮操作 */
    handleCheck() {
      const wxmId = this.rowData.wxmId;
      this.$confirm(
        "是否确认审核维修单号【" + this.rowData.wxmDjbh + "】的数据项?",
        "警告",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(function () {
          return checkWxm(wxmId);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("审核成功");
        })
        .catch(() => {});
    },
    /** 撤回按钮操作 */
    handleBack() {
      const wxmId = this.rowData.wxmId;
      backCheckWxm(wxmId, this.backReason)
        .then((res) => {
          this.getList();
          this.check_remove = false;
          this.backReason = null;
          this.msgSuccess("撤回成功");
        })
        .catch(() => {
          this.msgError("撤回失败");
        });
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm("是否确认导出所有设备维修作业数据项?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.exportLoading = true;
          return exportModelRepair(queryParams);
        })
        .then((response) => {
          this.download(response.msg);
          this.exportLoading = false;
        })
        .catch(() => {});
    },
  },
};
</script>

<style lang="scss" scoped></style>
